package com.eecs393.drymouth;

import org.json.JSONException;
import org.json.JSONObject;

import android.test.ActivityInstrumentationTestCase2;

public class ResultsValidation extends ActivityInstrumentationTestCase2<ConditionResults> {

	private final static String J_STRING = "[{\"c_id\":\"1\",\"c_name\":\"Disease1\",\"score\":\"0.6000\"},{\"c_id\":\"2\",\"c_name\":\"Disease2\",\"score\":\"0.5000\"}]";
	private ConditionResults cr;
//	private TextView display;
	private final String testUrl = "http://veysel.case.edu/drymouth/suggest/json/headache/1";
	
	
	public ResultsValidation() {
		super("com.eecs393.drymouth.conditionresults", ConditionResults.class);
	}

	protected void setUp() throws Exception {
		super.setUp();
		cr = new ConditionResults();	
		
		/*ConditionResults mainActivity = getActivity();
		display = (TextView) mainActivity.findViewById(R.id.Button_submitsearch);*/
	}

	public void testParseJSONs() throws JSONException{
		JSONObject jObj1 = new JSONObject("{\"c_id\":\"1\",\"c_name\":\"Disease1\",\"score\":\"0.6000\"}");
		JSONObject jObj2 = new JSONObject("{\"c_id\":\"2\",\"c_name\":\"Disease2\",\"score\":\"0.5000\"}");
		
		cr.parseJSONs(J_STRING);
		
		boolean check1 = jObj1.toString().equals(cr.getJSON(0).toString());
		boolean check2 = jObj2.toString().equals(cr.getJSON(1).toString());
		
		assertTrue(check1 && check2);
	}
	
	public void testFillConditions(){
		String[] conditions = new String[5];
		
		conditions[0] = "CLICK HERE TO BEGIN A NEW SEARCH";
		conditions[1] = "Condition Suggestions:";
		conditions[2] = "Rank: 1\nCondition: Disease1\nScore: 0.6000";
		conditions[3] = "Rank: 2\nCondition: Disease2\nScore: 0.5000";
		conditions[4] = "CLICK HERE TO BEGIN A NEW SEARCH";
		
		cr.parseJSONs(J_STRING);
		
		cr.fillConditions();
		
		boolean check = true;
		
		for (int i = 0; i < 5; i++){
			String c1 = conditions[i];
			String c2 = cr.getCondition(i);
			check = check && c1.equals(c2);
		}
		
		assertTrue(check);
	}
	
	public void testConnect(){
		cr.connect(testUrl);
		String expected = "Rank: 1\nCondition: Brain tumor - children\nScore: 0.6000";
		cr.parseJSONs(cr.getRawData());
		cr.fillConditions();
		assertTrue(cr.getCondition(2).equals(expected));
	}
	
	/*public void testListOnScreen(){
		DisplayMetrics metrics = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
		
		int fullWidth = metrics.widthPixels;
		int fullHeight = metrics.heightPixels;
		
		int[] viewLocation = new int[2];
		display.getLocationOnScreen(viewLocation);
		
		Rect outRect = new Rect();
		display.getDrawingRect(outRect);
		
		assertTrue("Submit button off the right of the screen", fullWidth  > outRect.width() + viewLocation[0]);
		assertTrue("Submit button off the bottom of the screen", fullHeight > outRect.height() + viewLocation[1]);
	}*/
}
